lib/commit: Add devino_cache_hits to txn stats
authorJonathan Lebon <jonathan@jlebon.com>
Fri, 2 Nov 2018 19:39:34 +0000 (15:39 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 5 Nov 2018 14:08:54 +0000 (14:08 +0000)
I found this useful while hacking on rpm-ostree but I think it might be
useful enough to upstream. This stat is really helpful for validating
that a pipeline is hitting the devino cache sweet spot.

Closes: #1772
Approved by: cgwalters

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo.h
src/ostree/ot-builtin-commit.c
tests/test-basic-user.sh

index 134024b8438d007728a8ce5fa2d43df1524bd5b8..52bc5d29c67dba977e57045477ca59132464a726 100644 (file)
@@ -3338,6 +3338,9 @@ write_content_to_mtree_internal (OstreeRepo                  *self,
               if (!glnx_shutil_rm_rf_at (dfd_iter->fd, name, cancellable, error))
                 return FALSE;
             }
+          g_mutex_lock (&self->txn_lock);
+          self->txn.stats.devino_cache_hits++;
+          g_mutex_unlock (&self->txn_lock);
           return TRUE; /* Early return */
         }
     }
@@ -3469,6 +3472,10 @@ write_content_to_mtree_internal (OstreeRepo                  *self,
       if (!ostree_mutable_tree_replace_file (mtree, name, loose_checksum,
                                              error))
         return FALSE;
+
+      g_mutex_lock (&self->txn_lock);
+      self->txn.stats.devino_cache_hits++;
+      g_mutex_unlock (&self->txn_lock);
     }
   /* Next fast path - we can "adopt" the file */
   else if (can_adopt)
index 829164ba92f0eab93aa0eb430990d11e7f891d30..007cbeddc3a78c3734d096833fda33b5dc230105 100644 (file)
@@ -291,8 +291,9 @@ struct _OstreeRepoTransactionStats {
   guint content_objects_total;
   guint content_objects_written;
   guint64 content_bytes_written;
+  guint devino_cache_hits;
 
-  guint64 padding1;
+  guint   padding1;
   guint64 padding2;
   guint64 padding3;
   guint64 padding4;
index 535239bece48c91d03324108a716dd323c89b7b9..b7c61a9e20a1621d366811b00d29d21209086de7 100644 (file)
@@ -835,6 +835,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
       g_print ("Metadata Written: %u\n", stats.metadata_objects_written);
       g_print ("Content Total: %u\n", stats.content_objects_total);
       g_print ("Content Written: %u\n", stats.content_objects_written);
+      g_print ("Content Cache Hits: %u\n", stats.devino_cache_hits);
       g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written);
     }
   else
index bd95f5ed5ea4a16f26dfef3b1bca58c531f61f5a..7bdb6a0ce232c8a7255b597f941c62255b7b52a5 100755 (executable)
@@ -117,9 +117,10 @@ assert_file_has_content ls.txt "^-006.. ${newuid} ${newgid} .*/baz/cow"
 
 # But --devino-canonical should override that
 $OSTREE commit ${COMMIT_ARGS} --owner-uid ${newuid} --owner-gid ${newgid} \
-        -I -b test2-devino-test --tree=dir=test2-checkout
+        -I -b test2-devino-test --table-output --tree=dir=test2-checkout > out.txt
 $OSTREE ls test2-devino-test /baz/cow > ls.txt
 assert_file_has_content ls.txt "^-006.. ${myuid} ${mygid} .*/baz/cow"
+assert_file_has_content out.txt "Content Cache Hits: [1-9][0-9]*"
 
 $OSTREE refs --delete test2-{linkcheckout,devino}-test
 echo "ok commit with -I"